package app.myproject.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import app.myproject.model.EventVO;

public class EventValidator implements Validator {

	@Override
	public boolean supports(Class clazz) {
		//just validate the Event instances
		return EventVO.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		// Check Name
		ValidationUtils.rejectIfEmptyOrWhitespace(
				errors, "name",	"required.name", "Name is required.");

		EventVO event = (EventVO)target;

		if(("Admin".equalsIgnoreCase(event.getName()))){
			errors.rejectValue("name", "invalid.name");
		}

	}

}
